﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClientRegister
{
    public partial class AddTeacherForm : Form
    {

        SynchronizeData sync = new SynchronizeData();

        GetNextID getID = new GetNextID();

        DataSet dsGender, dsSub;
        string idGender, idSub;

        public AddTeacherForm()
        {
            InitializeComponent();
        }

        private void AddTeacherForm_Load(object sender, EventArgs e)
        {
            ////Load du lieu chuyen mon cua giao vien tu server
            //sync.GetDataForInsertMethodWithNoneID(sync.TeacherTeachTb, sync.insertcol);
            //sync.GetDataForUpdateMethodWithNoneID(sync.TeacherTeachTb, sync.updatecol);

            ////Load du lieu giao vien tu server
            //sync.GetDataForInsertMethodWithID(sync.TeacherTb, sync.insertcol);
            //sync.GetDataForInsertMethodWithID(sync.TeacherTb, sync.updatecol);

            //Load combobox gioi tinh
            GenderDataProvider gend = new GenderDataProvider();
            dsGender = gend.loadDs();
            cbbGender.DataSource = dsGender.Tables[0];
            cbbGender.DisplayMember = "Gender";
            cbbGender.ValueMember = "IDGender";

            //Load combobox mon hoc
            SubjectsDataProvider load = new SubjectsDataProvider();
            dsSub = load.LoadSubject();
            cbbsub.DataSource = dsSub.Tables[0];
            cbbsub.DisplayMember = "SubjectName";
            cbbsub.ValueMember = "ID";
        }

        private void cbbGender_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbGender.SelectedValue.ToString() == "System.Data.DataRowView") return;
            else
            {
                idGender = cbbGender.SelectedValue.ToString();
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbsub.SelectedValue.ToString() == "System.Data.DataRowView") return;
            else
            {
                idSub = cbbsub.SelectedValue.ToString();
            }
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            //string xml = "", xmlTeach = "";
            string lastID = getID.getLastID(getID.TeacherTB, getID.IDCol);
            string ID = getID.NextID(lastID, getID.prefixID);
            TeacherDataProvider addteach = new TeacherDataProvider();
            int result0 = addteach.AddTeacher(ID,txtName.Text, idGender, txtBirth.Text, txtPhone.Text, txtEmail.Text, txtAddr.Text);
            if (result0 != 0)
            {


                ////Chuyen thong tin giao vien moi len server
                //xml = addteach.SelectAndConvertXMLTech(idTeach);
                //sync.transfDataForInsertMethod(xml, sync.TeacherTb);

                //Insert chuyen mon cua giao vien vao ban
                TeacherTeachDataProvider teach = new TeacherTeachDataProvider();
                int result = teach.addTeacherTeach(ID, idSub);
                if (result != 0)
                {
                    ////Chuyen thong tin chuyen mon cua giao vien len server
                    //xmlTeach = teach.ConvertTeacherTeachToXML(idTeach, int.Parse(idSub));
                    //sync.transfDataForInsertMethod(xmlTeach, sync.insertcol);

                    MessageBox.Show("Đã thêm giáo viên mới");
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
